# @Time    : 2022/8/30 20:29
# @Author  : ysh 
# @File    : et_err
# @Software: PyCharm

from common.result import result_code
from common.result import err_msg


class EtError(Exception):
    """
    自定义错误信息
    """

    def __init__(self, result_cont: result_code.ResultCont, msg_obj: err_msg.ErrMsg, message="", tips="", err_reason="",
                 err_type=None):
        msg_obj.reason = err_reason or msg_obj.reason
        msg_obj.contact = tips or msg_obj.contact
        msg_obj.text = message or msg_obj.text
        self.result_cont = result_cont
        self.err_msg = msg_obj
        self.err_type = err_type or "EtError"


class NotFoundErr(EtError):
    """方法不存在"""
    def __init__(self, err_obj: result_code.ResultCont, msg_obj: err_msg.ErrMsg, message="", tips="", err_reason=""):
        self.tips = tips
        self.err_reason = err_reason
        self.err_type = "NotFoundErr"
        super().__init__(
            result_cont=err_obj, msg_obj=msg_obj, tips=self.tips, err_reason=self.err_reason, err_type=self.err_type,
            message=message
        )

    __module__ = 'builtins'


class NotDataErr(EtError):
    """数据不存在"""

    def __init__(self, err_obj: result_code.ResultCont, msg_obj: err_msg.ErrMsg, message="", tips="", err_reason=""):
        self.code = err_obj.Code
        self.err = err_obj.Msg
        self.tips = tips
        self.err_reason = err_reason
        self.err_type = "NotDataErr"
        super().__init__(
            result_cont=err_obj, msg_obj=msg_obj, tips=self.tips, err_reason=self.err_reason, err_type=self.err_type,
            message=message
        )

    __module__ = 'builtins'


class AuthErr(EtError):
    """权限错误"""

    def __init__(self, err_obj: result_code.ResultCont, msg_obj: err_msg.ErrMsg, message="", tips="", err_reason=""):
        self.code = err_obj.Code
        self.err = err_obj.Msg
        self.tips = tips
        self.err_reason = err_reason
        self.err_type = "AuthErr"
        super().__init__(
            result_cont=err_obj, msg_obj=msg_obj, tips=self.tips, err_reason=self.err_reason, err_type=self.err_type,
            message=message
        )

    __module__ = 'builtins'


class ParamErr(EtError):
    """参数错误"""

    def __init__(self, err_obj: result_code.ResultCont, msg_obj: err_msg.ErrMsg, message="", tips="", err_reason=""):
        self.code = err_obj.Code
        self.err = err_obj.Msg
        self.tips = tips
        self.err_reason = err_reason
        self.err_type = "ParamErr"
        super().__init__(
            result_cont=err_obj, msg_obj=msg_obj, tips=self.tips, err_reason=self.err_reason, err_type=self.err_type,
            message=message
        )

    __module__ = 'builtins'


class MethodErr(EtError):
    """方法错误"""

    def __init__(self, err_obj: result_code.ResultCont, msg_obj: err_msg.ErrMsg, message="", tips="", err_reason=""):
        self.code = err_obj.Code
        self.err = err_obj.Msg
        self.tips = tips
        self.err_reason = err_reason
        self.err_type = "MethodErr"
        super().__init__(
            result_cont=err_obj, msg_obj=msg_obj, tips=self.tips, err_reason=self.err_reason, err_type=self.err_type,
            message=message
        )

    __module__ = 'builtins'


class AssertErr(EtError):
    """断言错误"""

    def __init__(self, err_obj: result_code.ResultCont, msg_obj: err_msg.ErrMsg, message="", tips="", err_reason=""):
        self.code = err_obj.Code
        self.err = err_obj.Msg
        self.tips = tips
        self.err_reason = err_reason
        self.err_type = "AssertErr"
        super().__init__(
            result_cont=err_obj, msg_obj=msg_obj, tips=self.tips, err_reason=self.err_reason, err_type=self.err_type,
            message=message
        )

    __module__ = 'builtins'


class SqlErr(EtError):
    """数据库错误"""

    def __init__(self, err_obj: result_code.ResultCont, msg_obj: err_msg.ErrMsg, message="", tips="", err_reason=""):
        self.code = err_obj.Code
        self.err = err_obj.Msg
        self.tips = tips
        self.err_reason = err_reason
        self.err_type = "SqlErr"
        super().__init__(
            result_cont=err_obj, msg_obj=msg_obj, tips=self.tips, err_reason=self.err_reason, err_type=self.err_type,
            message=message
        )

    __module__ = 'builtins'


class RedisErr(EtError):
    """redis错误"""

    def __init__(self, err_obj: result_code.ResultCont, msg_obj: err_msg.ErrMsg, message="", tips="", err_reason=""):
        self.code = err_obj.Code
        self.err = err_obj.Msg
        self.tips = tips
        self.err_reason = err_reason
        self.err_type = "RedisErr"
        super().__init__(
            result_cont=err_obj, msg_obj=msg_obj, tips=self.tips, err_reason=self.err_reason, err_type=self.err_type,
            message=message
        )

    __module__ = 'builtins'


class MongoErr(EtError):
    """mongo错误"""

    def __init__(self, err_obj: result_code.ResultCont, msg_obj: err_msg.ErrMsg, message="", tips="", err_reason=""):
        self.code = err_obj.Code
        self.err = err_obj.Msg
        self.tips = tips
        self.err_reason = err_reason
        self.err_type = "MongoErr"
        super().__init__(
            result_cont=err_obj, msg_obj=msg_obj, tips=self.tips, err_reason=self.err_reason, err_type=self.err_type,
            message=message
        )

    __module__ = 'builtins'


class OtherErr(EtError):
    """其他错误"""

    def __init__(self, err_obj: result_code.ResultCont, msg_obj: err_msg.ErrMsg, message="", tips="", err_reason=""):
        self.code = err_obj.Code
        self.err = err_obj.Msg
        self.tips = tips
        self.err_reason = err_reason
        self.err_type = "OtherErr"
        super().__init__(
            result_cont=err_obj, msg_obj=msg_obj, tips=self.tips, err_reason=self.err_reason, err_type=self.err_type,
            message=message
        )

    __module__ = 'builtins'
